package 从尾到头打印链表;

import java.util.ArrayList;
import java.util.Stack;

public class Solution {
    public static ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        Stack<Integer> stack = new Stack<>();
        ArrayList<Integer> arrayList = new ArrayList<>();
        ListNode head = listNode;
        while (head != null) {
            stack.push(head.val);
            head = head.next;
        }

        while (!stack.empty()) {
            arrayList.add(stack.pop());
        }
        return arrayList;
    }
}
